package com.quwan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quwan.app.vo.MemberDynamicDTO;
import com.quwan.entity.TDynamicFollow;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * @author quan
 * @date 2021-07-24 9:52
 */


public interface TDynamicFollowMapper extends BaseMapper<TDynamicFollow> {
    @Select(" select d.id,d.title,d.status,d.topic, " +
            " m.nick_name,m.img_url,m.service_level,m.id as mId ," +
            " (select count(1) from t_dynamic_follow where dynamic_id = d.id and status = 1 ) as follow, " +
            " (select count(1) from t_dynamic_comment where dynamic_id = d.id ) as comment, " +
            " (select count(1) from t_member_follow as f where f.un_lock=  concat(#{id},d.m_id)  and  f.status =1 ) as follower, " +
            " (select group_concat(url) from t_member_dynamic_file where dynamic_id =d.id) imgs " +
            " from t_member_dynamic as d left  join t_member as m  on d.m_id =m.id " +
            " where exists(select 1 from t_dynamic_follow f where f.m_id=#{id} and f.status =1 and f.dynamic_id = d.id ) and  d.status = 1 order by d.add_time desc")
    Page<Map<String, Object>> selectFollowDynamicListByMId(Page<Object> objectPage, @Param("id") String id);
}